using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

namespace CS
{
    public class VolumeControl : MonoBehaviour
    {
        private static ColorAdjustments mColorAdjustments;
        private Volume mVolume;
        void Start()
        {
            mVolume = GetComponent<Volume>();
           if( mVolume.profile.TryGet(typeof(ColorAdjustments), out ColorAdjustments colorAdjustments))
           {
               mColorAdjustments = colorAdjustments;
               mColorAdjustments.postExposure.Override(0.43f);
                mColorAdjustments.colorFilter.Override(Color.white);
            }
   
        }

        /// <summary>
        /// 开启转场黑幕
        /// </summary>
        /// <param name="entertime"></param>
        public static void StartBlackScene(Action enterCallBack =null,Action exitCallBacl = null,float enterTime = 0.05f,float exitTime = 2.0f)
        {
            DOTween.KillAll();
            DOTween.To(() => mColorAdjustments.postExposure.value, x =>
            {
                mColorAdjustments.postExposure.value = x;
            },-10f,enterTime).SetEase(Ease.InOutSine).OnComplete(() =>
            {
                enterCallBack?.Invoke();
                EndBlackScene(exitTime,exitCallBacl);
            });
     
        }

        /// <summary>
        /// 结束转场黑幕
        /// </summary>
        /// <param name="time"></param>
        public static void EndBlackScene(float time =1.0f,Action callBack = null)
        {
            DOTween.To(() => mColorAdjustments.postExposure.value, x =>
            {
                mColorAdjustments.postExposure.value = x;
            },0.2f,time).SetEase(Ease.InOutSine).OnComplete(() => { callBack?.Invoke();});
        }
    }
}
